/**
 * Copyleft (C) 2023-2024 maminjie <canpool@163.com>
 * SPDX-License-Identifier: BSD-3-Clause
 **/
#include "matcheckbox.h"
#include "matcheckable_p.h"
#include "matcheckbox_p.h"
#include <QPropertyAnimation>
#include <QSignalTransition>
#include <QState>

QX_MATERIAL_BEGIN_NAMESPACE

/*!
 *  \class MatCheckBoxPrivate
 *  \internal
 */

/*!
 *  \internal
 */
MatCheckBoxPrivate::MatCheckBoxPrivate(MatCheckBox *q)
    : MatCheckablePrivate(q)
{
}

/*!
 *  \internal
 */
MatCheckBoxPrivate::~MatCheckBoxPrivate()
{
}

/*!
 *  \internal
 */
void MatCheckBoxPrivate::init()
{
    Q_Q(MatCheckBox);

    checkedState->assignProperty(checkedIcon, "iconSize", 24);
    uncheckedState->assignProperty(checkedIcon, "iconSize", 0);

    QPropertyAnimation *animation;

    animation = new QPropertyAnimation(checkedIcon, "iconSize", q);
    animation->setDuration(300);
    uncheckedTransition->addAnimation(animation);

    animation = new QPropertyAnimation(checkedIcon, "iconSize", q);
    animation->setDuration(1300);
    checkedTransition->addAnimation(animation);

    animation = new QPropertyAnimation(checkedIcon, "opacity", q);
    animation->setDuration(440);
    checkedTransition->addAnimation(animation);

    animation = new QPropertyAnimation(checkedIcon, "opacity", q);
    animation->setDuration(440);
    uncheckedTransition->addAnimation(animation);

    animation = new QPropertyAnimation(uncheckedIcon, "opacity", q);
    animation->setDuration(440);
    checkedTransition->addAnimation(animation);

    animation = new QPropertyAnimation(uncheckedIcon, "opacity", q);
    animation->setDuration(440);
    uncheckedTransition->addAnimation(animation);

    animation = new QPropertyAnimation(uncheckedIcon, "color", q);
    animation->setDuration(440);
    checkedTransition->addAnimation(animation);

    animation = new QPropertyAnimation(uncheckedIcon, "color", q);
    animation->setDuration(440);
    uncheckedTransition->addAnimation(animation);
}

/*!
 *  \class MatCheckBox
 */

MatCheckBox::MatCheckBox(QWidget *parent) : MatCheckable(*new MatCheckBoxPrivate(this), parent)
{
    d_func()->init();
}

MatCheckBox::~MatCheckBox()
{
}

QX_MATERIAL_END_NAMESPACE
